package com.example.myapplication.tools;

import android.content.Context;
import android.content.SharedPreferences;

import com.example.myapplication.WordApp;

public class Preferences {

    private static Preferences mInstance;

    private SharedPreferences cache;

    private Preferences()
    {
        cache = WordApp.AppCtx.getSharedPreferences(
                "local",
                Context.MODE_PRIVATE);
    }

    public static Preferences getInstance() {
        if(mInstance == null){
            mInstance = new Preferences();
        }
        return mInstance;
    }

    String KEY_WORD_DB = "KEY_WORD_DB";
    public void saveWordDB(int db) {
        cache.edit().putInt(KEY_WORD_DB, db).apply();
    }

    public int loadWordDB() {
        return cache.getInt(KEY_WORD_DB, 0);
    }


    String KEY_IDX_START = "KEY_IDX_START";
    public void saveIdxStart(int idx) {
        cache.edit().putInt(KEY_IDX_START, idx).apply();
    }

    public int loadIdxStart() {
        return cache.getInt(KEY_IDX_START, 1);
    }

    String KEY_IDX_END = "KEY_IDX_END";
    public void saveIdxEnd(int idx) {
        cache.edit().putInt(KEY_IDX_END, idx).apply();
    }

    public int loadIdxEnd() {
        return cache.getInt(KEY_IDX_END, 1);
    }


}
